home *** CD-ROM | disk | FTP | other *** search
- /* indigo_obuffer.cc
-
- Obuffer for Silicon Graphics Indigo written by
- Tobias Bading (bading@cs.tu-berlin.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #ifdef IRIX
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <iostream.h>
- extern "C" {
- #include <audio.h>
- }
-
- #include "header.h"
- #include "obuffer.h"
- #include "args.h"
-
- IndigoObuffer::IndigoObuffer (uint32 number_of_channels, MPEG_Args *maplay_args)
- {
- #ifdef DEBUG
- if (!number_of_channels || number_of_channels > MAXCHANNELS)
- {
- cerr << "IndigoObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
- exit (1);
- }
- #endif
- channels = number_of_channels;
- for (int i = 0; i < number_of_channels; ++i)
- bufferp[i] = buffer + i;
-
- // open an audio port and configure it:
- ALconfig config;
- if (!(config = ALnewconfig ()))
- {
- cerr << "ALnewconfig failed!\n";
- exit (1);
- }
- ALsetwidth (config, AL_SAMPLE_16);
- if (channels == 1)
- ALsetchannels (config, AL_MONO);
- else
- ALsetchannels (config, AL_STEREO);
- if (!(port = ALopenport ("MPEG audio player", "w", config)))
- {
- cerr << "can't allocate an audio port!\n";
- exit (1);
- }
-
- // set sample rate:
- long pvbuffer[2] = { AL_OUTPUT_RATE, 0 };
- pvbuffer[1] = maplay_args->MPEGheader->frequency ();
- ALsetparams (AL_DEFAULT_DEVICE, pvbuffer, 2);
- ALfreeconfig (config);
- }
-
-
- IndigoObuffer::~IndigoObuffer (void)
- {
- while (ALgetfilled (port) > 0)
- sleep (1);
- ALcloseport (port);
- }
-
-
- void IndigoObuffer::append (uint32 channel, int16 value)
- {
- #ifdef DEBUG
- if (channel >= channels)
- {
- cerr << "illegal channelnumber in IndigoObuffer::append()!\n";
- exit (1);
- }
- if (bufferp[channel] - buffer >= OBUFFERSIZE)
- {
- cerr << "IndigoObuffer: buffer overflow!\n";
- exit (1);
- }
- #endif
- *bufferp[channel] = value;
- bufferp[channel] += channels;
- }
-
- #ifdef SEEK_STOP
- void IndigoObuffer::clear_buffer(void)
- {
- }
-
- void IndigoObuffer::set_stop_flag(void)
- {
- }
- #endif // SEEK_STOP
-
- void IndigoObuffer::write_buffer (int)
- {
- ALwritesamps (port, buffer, (long)(bufferp[0] - buffer));
- for (int i = 0; i < channels; ++i)
- bufferp[i] = buffer + i;
- }
-
- Obuffer *create_obuffer(MPEG_Args *maplay_args)
- {
- Obuffer *buffer;
-
- enum e_mode mode = maplay_args->MPEGheader->mode();
- enum e_channels which_channels = maplay_args->which_c;
-
- if (mode == single_channel || which_channels != both)
- buffer = new IndigoObuffer (1, maplay_args);
- else
- buffer = new IndigoObuffer (2, header);
-
- return(buffer);
- }
-
- #endif // IRIX
-